<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<script type="text/javascript" src="<c:url value="/js/html5/html5.min.js"/>"> </script>
<script type="text/javascript" src="<c:url value="/js/respond/respond.min.js"/> "></script>
<script type="text/javascript" src="<c:url value="/js/PIE/2.0/PIE_IE678.js"/>"></script>

<link href="<c:url value="/css/H-ui.min.css"/>" rel="stylesheet" type="text/css" />
<link href="<c:url value="/css/H-ui.login.css"/>" rel="stylesheet" type="text/css" />
<link href="<c:url value="/css/Hui-iconfont/1.0.1/iconfont.css"/>" rel="stylesheet" type="text/css" />
<%--分页--%>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/layer/laypage.css"/>">
<title>项目列表</title>
</head>
<body class="pos-r">
	<div>
		<nav class="breadcrumb">
			<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 项目管理 <span class="c-gray en">&gt;</span> 项目列表 <a class="btn btn-success radius r mr-20" style="line-height: 1.6em; margin-top: 3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
		</nav>
		<div class="pd-20">
			<div class="text-c">
				<form action="<c:url value="/admin/project/list/0"/>">
					项目状态：<select name="status">
						<option value=""></option>
						<option value="waiting_verified">众筹等待审核</option>
						<option value="waiting_pay">众筹等待支付保证金</option>
						<option value="waiting_invested">众筹中</option>
						<option value="verify_failed">众筹审核失败</option>
						<option value="invest_failed">众筹投资失败</option>
						<option value="invest_delay">众筹延期</option>
						<option value="delay_verify">众筹延期审核中</option>
						<option value="invest_success">众筹投资成功</option>
						<option value="project_success">众筹项目已启动</option>
						<option value="project_failed">众筹项目失败</option>
						<option value="project_cancel">众筹项目被取消</option>
						<option value="project_end">众筹启动后被终止</option>
					</select> &nbsp;城市<input type="text" name="city" value="${queryData.city}" />&nbsp;项目名称：<input type="text" name="projectName" value="${queryData.projectName}" />
					<button class="btn btn-success" type="submit">
						<i class="Hui-iconfont">&#xe665;</i> 搜项目
					</button>
				</form>
			</div>
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<!-- <span class="l"><a class="btn btn-primary radius" onclick="product_add('添加项目',<c:url value="/admin/project/toCreate"/>')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加项目</a></span>-->
				<span class="r">共有数据：<strong>${viewData.count}</strong> 条
				</span>
			</div>
			<div class="mt-20">
				<table class="table table-border table-bordered table-bg table-hover table-sort">
					<thead>
						<tr class="text-c">
							<th width="150">产品名称</th>
							<th width="60">项目所在城市</th>
							<th width="100">股权类型</th>
							<th width="100">结束时间</th>
							<th width="60">发布状态</th>
							<th width="100">操作</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${viewData.result}" var="prolist">
							<tr class="text-c va-m">

								<td>${prolist.projectName}</td>
								<td>${prolist.projectCity}</td>
								<td>${prolist.stockType}</td>
								<td><fmt:formatDate value="${prolist.endDate}" pattern="yyyy-MM-dd" var="endDate" /> ${endDate}</td>
								<td><c:if test="${prolist.status=='waiting_verified'}">
                                	众筹等待审核
                            	</c:if> <c:if test="${prolist.status=='waiting_pay'}">
                                	众筹等待支付保证金
                            	</c:if> <c:if test="${prolist.status=='verify_failed'}">
                                	众筹审核失败
                            	</c:if> <c:if test="${prolist.status=='waiting_invested'}">
                                	众筹中
                            	</c:if> <c:if test="${prolist.status=='invest_success'}">
                                	众筹投资成功
                            	</c:if> <c:if test="${prolist.status=='invest_failed'}">
                                	众筹投资失败
                            	</c:if> <c:if test="${prolist.status=='invest_delay'}">
                                	众筹延期
                            	</c:if> <c:if test="${prolist.status=='delay_verify'}">
                                	众筹延期审核中
                            	</c:if> <c:if test="${prolist.status=='project_success'}">
                                	众筹项目已启动
                            	</c:if> <c:if test="${prolist.status=='project_failed'}">
                                	众筹项目失败
                            	</c:if> <c:if test="${prolist.status=='project_cancel'}">
                                	众筹项目被取消
                            	</c:if> <c:if test="${prolist.status=='project_end'}">
                                	众筹项目被终止
                            	</c:if></td>
								<td class="td-manage"><c:if test="${prolist.status=='waiting_verified'}">
											 &nbsp;<a href="<c:url value="/admin/project/toUpdateEarnestPercent?projectId=${prolist.id}" />" title="保证金比例">设置或修改保证金比例&nbsp;</a>
									</c:if> <c:choose>
										<c:when test="${prolist.status=='waiting_verified'}">
											<a id="a_href" style="text-decoration: none" onClick="product_verify(this,'${prolist.id}','${prolist.investorEarnestPercent}','${prolist.projectEarnestPercent}')" href="javascript:;" title="审核">审核</a>
										</c:when>
										<c:when test="${prolist.status=='invest_delay'}">
											<a style="text-decoration: none" class="ml-5" onClick="product_delay(this,${prolist.id})" href="javascript:;" title="是否延期">延期</a>
										</c:when>
									</c:choose> <c:if test="${prolist.status != 'waiting_verified' && prolist.status != 'waiting_pay' && prolist.status != 'verify_failed'}">
											&nbsp;<a href="<c:url value="/admin/project/projectInvestor?id=${prolist.id}" />">查看投资人</a>
									</c:if> <c:if test="${ prolist.status == 'project_success'}">
											&nbsp;<a href="<c:url value="/admin/finance/list?projectId=${prolist.id}"/>">查看财务报表</a>									
											&nbsp;<a href="#" onClick="stopProject(this,${prolist.id})">终止项目</a>
									</c:if> <c:if test="${(prolist.startStatus || prolist.status == 'invested_success') && prolist.status != 'project_success' && prolist.status != 'project_cancel' && prolist.status != 'project_end'}">
											&nbsp;<a href="#" onClick="startProject(this,${prolist.id})">启动项目</a>
									</c:if>&nbsp;<a href="<c:url value="/admin/project/projectDetail?id=${prolist.id}" />">查看详情</a></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<div id="pagelayer" style="float: right; margin-top: 10px;"></div>
			</div>
		</div>
	</div>
	<%--分页--%>
	<script type="text/javascript" src="<c:url value="/js/laypage/1.2/laypage.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/jquery/1.9.1/jquery.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/layer/1.9.3/layer.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/h-ui/2.3/H-ui.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/h-ui/2.3/H-ui.admin.js"/>"></script>
	<script type="text/javascript">
    function product_verify(obj, id,investorEarnest,projectEarnest) {
    	if(investorEarnest<=0){
    		layer.msg("请录入正确的投资保证金比例",{icon: 6, time: 2000});
    		return -1;
    	}
    	if(projectEarnest<=0){
    		layer.msg("请录入正确的项目保证金比例",{icon: 6, time: 2000});
    		return -1;
    	}
        layer.confirm('该项目是否审核通过？', {
                    btn: ['通过', '不通过', '取消'],
                    shade: false
                },
                function () {
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        data: {projectId: id, passOrNot: "true"},
                        url: "<c:url value="/admin/project/verify"/>",
                        success: function (data, textStatus) {
                            layer.msg(data.msg, {icon: 6, time: 1000}, function () {
                                location.reload(true);
                            });
                        },
                        error: function (data) {
                            layer.msg(data.msg, {icon: 5, time: 1000});
                        }
                    });
                },
                function () {
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        data: {projectId: id, passOrNot: "false"},
                        url: "<c:url value="/admin/project/verify"/>",
                        success: function (data, textStatus) {
                            layer.msg(data.msg, {icon: 6, time: 1000}, function () {
                                location.reload(true);
                            });
                        },
                        error: function (data) {
                            layer.msg(data.msg, {icon: 5, time: 1000});
                        }
                    });
                });
    }
    /*延期项目*/
    function product_delay(obj, id) {
        layer.confirm('是否同意该项目延期？', {
                    btn: ['是', '否', '取消'],
                    shade: false
                },
                function () {
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        data: {projectId: id, passOrNot: "true"},
                        url: "<c:url value="/admin/project/postpone"/>",
                        success: function (data, textStatus) {
                            layer.msg(data.msg, {icon: 6, time: 1000}, function () {
                                location.reload(true);
                            });
                        },
                        error: function (data) {
                            layer.msg(data.msg, {icon: 5, time: 1000});
                        }
                    });
                }, function () {
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        data: {projectId: id, passOrNot: "false"},
                        url: "<c:url value="/admin/project/postpone"/>",
                        success: function (data, textStatus) {
                            layer.msg(data.msg, {icon: 6, time: 1000}, function () {
                                location.reload(true);
                            });
                        },
                        error: function (data) {
                            layer.msg(data.msg, {icon: 5, time: 1000});
                        }
                    });
                });
    }  /*启动项目*/
                function startProject(obj, id) {
                    layer.confirm('是否启动项目？', {
                                btn: ['是', '取消'],
                                shade: false
                            },
                            function () {
                                $.ajax({
                                    type: "post",
                                    dataType: "json",
                                    data: {id: id},
                                    url: "<c:url value="/admin/project/startProject"/>",
                                    success: function (data, textStatus) {
                                        layer.msg(data.msg, {icon: 6, time: 1000}, function () {
                                            location.reload(true);
                                        });
                                    },
                                    error: function (data) {
                                        layer.msg(data.msg, {icon: 5, time: 1000});
                                    }
                                });
                            });
                }
                /*终止项目*/
                function stopProject(obj, id) {
                    layer.confirm('是否终止项目？', {
                                btn: ['是', '取消'],
                                shade: false
                            },
                            function () {
                                $.ajax({
                                    type: "post",
                                    dataType: "json",
                                    data: {id: id},
                                    url: "<c:url value="/admin/project/stopProject"/>",
                                    success: function (data, textStatus) {
                                        layer.msg(data.msg, {icon: 6, time: 1000}, function () {
                                            location.reload(true);
                                        });
                                    },
                                    error: function (data) {
                                        layer.msg(data.msg, {icon: 5, time: 1000});
                                    }
                                });
                            });
                }
    
    
	$(function(){
		//        分页
		laypage({
			cont: $('#pagelayer'), //容器。值支持id名、原生dom对象，jquery对象,
			pages: "${viewData.pages}", //总页数
			skin: '#5eb95e', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
			groups: "7" ,//连续显示分页数
			skip: true, //是否开启跳页
			curr: "${viewData.page}", //获取hash值为fenye的当前页
			hash: '//', //自定义hash值
			jump: function(e, first){ //触发分页后的回调
				var pagesize = "${viewData.pageSize}";
				var url = e.curr;
				if(!first){//一定要加此判断，否则初始时会无限刷新
					location.href = url;
				}
			}
		});
	})
</script>
</body>
</html>